#include <bits/stdc++.h>

using namespace std;

const int MAXN = 450;
const int inf = 0x3f3f3f3f;

typedef struct {int v,w,nxt;} edge;

int h[MAXN],d[MAXN],now[MAXN],cnt=1,s,t,n,m,maxflow,tot;
edge e[MAXN*MAXN];

void link(int x,int y,int w){
	e[++cnt] = (edge){y,w,h[x]};h[x] = cnt;
	e[++cnt] = (edge){x,0,h[y]};h[y] = cnt;
}

bool bfs(){
	memset(d,0,sizeof(d));
	queue<int> q;
	q.push(s);
	d[s] = 1;now[s] = h[s];
	while(q.size()){
		int x = q.front();q.pop();
		for(int i = h[x];i;i = e[i].nxt){
			int y = e[i].v;
			if(!d[y] && e[i].w){
				d[y] = d[x] + 1;
				now[y] = h[y];
				q.push(y);
				if(y == t) return 1;
			}
		}
	}
	return 0;
}

int dinic(int x,int flow){
	if(x == t) return flow;
	int res = flow;
	for(int i = now[x];i && res;i = e[i].nxt){
		int y = e[i].v;now[x] = i;
		if(e[i].w && d[y] == d[x] + 1){
			int k = dinic(y,min(res,e[i].w));
			if(!k) d[y] = 0;
			res -= k;
			e[i].w -= k;
			e[i^1].w += k;
		}
	}
	return flow - res;
}

int main (){
	scanf("%d %d",&m,&n);
	s = 0,t = m+n+1;
	for(int i = 1;i <= m;i++){
		int x;scanf("%d",&x);tot += x;
		link(s,i,x);
	}
	for(int i = 1;i <= n;i++){
		int x;scanf("%d",&x);
		link(i+m,t,x);
	}
	for(int i = 1;i <= m;i++)
		for(int j = 1;j <= n;j++)
			link(i,j+m,1);
	int flow = 0;
	while(bfs()) while(flow = dinic(s,inf)) maxflow += flow;
	if(maxflow != tot) return puts("0"),0;
	puts("1");
	for(int i = 1;i <= m;i++){
		for(int j = h[i];j;j = e[j].nxt){
			int y = e[j].v;
			if(!e[j].w && y != s && y != t){
				printf("%d ",y-m);
			}
		}
		puts("");
	}
	return 0;
}
